package com.steven.concurrency.example.jihetongbu;

import com.steven.concurrency.annoations.NotThreadSafe;

import java.util.List;
import java.util.Vector;

/**
 * 当线程一在执行移除操作的时候 线程二正好在获取当前索引，遂就引起了异常
 */
@NotThreadSafe
public class VectorExam {

    private static List<Integer> list = new Vector<>();


    public static void main(String[] args) {

        while (true){
            for (int i = 0; i <10 ; i++) {
                list.add(i);
            }
            new Thread(() -> {
                for (int i = 0; i <list.size() ; i++) {
                    list.remove(i);
                }
            }).start();

            new  Thread(()->{
                for (int i = 0; i <list.size() ; i++) {
                    list.get(i);
                }
            }).start();
        }


    }
}
